package com.example.demo.model;

import com.example.demo.dataobject.OrderDO;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 订单
 */
public class Order implements Serializable {
    private String id;//主键
    private String orderNumber;//订单编号
    private Long userId;//用户Id
    private User user;//用户模型
    private String productId;//商品Id
    private String productDetailId;//商品详情Id
    private ProductDetail productDetail;//商品详情模型
    private Double totalPrice;//订单总价格
    private OrderStatus status;//订单状态
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime gmtCreated;//创建时间
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime gmtModified;//修改时间

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getProductDetailId() {
        return productDetailId;
    }

    public void setProductDetailId(String productDetailId) {
        this.productDetailId = productDetailId;
    }

    public ProductDetail getProductDetail() {
        return productDetail;
    }

    public void setProductDetail(ProductDetail productDetail) {
        this.productDetail = productDetail;
    }

    public Double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public LocalDateTime getGmtCreated() {
        return gmtCreated;
    }

    public void setGmtCreated(LocalDateTime gmtCreated) {
        this.gmtCreated = gmtCreated;
    }

    public LocalDateTime getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(LocalDateTime gmtModified) {
        this.gmtModified = gmtModified;
    }

    /**
     * 模型转换成数据库对象
     * @return OrderDO订单数据库对象
     */
    public OrderDO toDO(){
        OrderDO orderDO = new OrderDO();
        orderDO.setId(id);
        orderDO.setOrderNumber(orderNumber);
        orderDO.setUserId(userId);
        orderDO.setProductId(productId);
        orderDO.setProductDetailId(productDetailId);
        orderDO.setTotalPrice(totalPrice);
        orderDO.setStatus(status.toString());
        orderDO.setGmtCreated(gmtCreated);
        orderDO.setGmtModified(gmtModified);
        return orderDO;
    }
}
